package haw.pr2.A3.implementations;

import haw.pr2.A3.interfaces.*;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import static haw.pr2.A3.implementations.UtilityclassValues.*;
import static haw.pr2.A3.implementations.Entities.*;

/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class ContainerStowageImpl implements ContainerStowage {
    
    Bounded3DimStackImpl<Container> containerStack;
    
    Mass emptyMass, maxMass;
    
    
    private ContainerStowageImpl(int bay, int row, int tier) {
        containerStack=(Bounded3DimStackImpl<Container>) Bounded3DimStackImpl.valueOf(bay, row, tier, nullContainer());
        emptyMass=ZERO_MASS;
        maxMass=ZERO_MASS.add(CON_MAX_MASS.mul(bay*row*tier));
    }
    
    public static ContainerStowage valueOf(int bay, int row, int tier) {
        return new ContainerStowageImpl(bay, row, tier);
    } 

    @Override
    public Mass mass() {
        Mass res = emptyMass;
        Set<Container> container = this.getAll();
        for (Iterator<Container> it = container.iterator(); it.hasNext();) {
            Container con = it.next();
            res.add(con.mass());
        }
        return res;
    }

    @Override
    public BoundingBox boundingBox() {
        Set<Container> container=this.getAll();
        return EMPTY_BOUNDING_BOX.addAll(container);
    }

    @Override
    public Mass emptyMass() {
        return this.emptyMass;
    }

    @Override
    public Mass maxMass() {
        return this.maxMass;
    }

    @Override
    public boolean isEmpty() {
        return containerStack.isEmpty();
    }

    @Override
    public boolean isFull() {
        return containerStack.isFull();
    }

    @Override
    public void load(int bayNo, int rowNo, Container elem) {
        containerStack.load(bayNo, rowNo, elem);
    }

    @Override
    public void load(Container elem) {
        containerStack.load(elem);
    }

    @Override
    public void loadAll(Collection<Container> coll) {
        containerStack.loadAll(coll);
    }

    @Override
    public boolean tierIsEmpty(int bay, int row) {
        return containerStack.tierIsEmpty(bay, row);
    }

    @Override
    public boolean tierIsFull(int bay, int row) {
        return containerStack.tierIsFull(bay, row);
    }

    @Override
    public boolean contains(Object elem) {
        return containerStack.contains(elem);
    }

    @Override
    public boolean containsAll(Collection<?> coll) {
        return containerStack.containsAll(coll);
    }

    @Override
    public Container get(StowageLocation loc) {
        return containerStack.get(loc);
    }

    @Override
    public Set<Container> getAll() {
        return containerStack.getAll();
    }

    @Override
    public StowageLocation locationOf(Container elem) {
        return containerStack.locationOf(elem);
    }
    
   
}